//
//  QiyuView.swift
//  JiaoZiTaxi
//
//  Created by Hu Gang on 2023/12/8.
//

import Foundation
import QYSDK
import SwiftUI
import IQKeyboardManager

// 创建一个 UIViewControllerRepresentable 子类
struct QiyuViewController: UIViewControllerRepresentable {

   // 在这里定义您需要包装的UIKit视图控制器
   //private var viewController: QYSessionViewController?
   func makeUIViewController(context: Context) -> UIViewController {
      let source = QYSource()
      source.title = "Customer Service"
      source.urlString = ""

      let viewController = QYSDK.shared().sessionViewController() // 替换为您的自定义UIViewController
      // 在这里可以进行视图控制器的配置
      viewController?.sessionTitle = "Customer Service"
      viewController?.source = source
      viewController?.hidesBottomBarWhenPushed = true

      return viewController!
   }

   func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
      // 可以在需要时更新视图控制器
   }
}

struct QiyuView: View {
   @State private var isPresented = false

   var body: some View {
      NavigationView {
         Button("Present UIKit View Controller") {
            isPresented.toggle()
         }
         .sheet(isPresented: $isPresented) {
            QiyuViewController() // 使用 UIViewControllerRepresentable 包装的视图控制器
         }
      }
   }
}
